#include "common.h"
PUBLIC S4B DivideULLONG(PULLONG quotient,PULLONG remainder,ULLONG dividend,ULLONG divisor)
{
    quotient->high=0;
	remainder->high=0;
    __asm__ __volatile__(
    "divl %%ebx\n\t"
    :"=a"(quotient->low),"=d"(remainder->low)    
    :"d"(dividend.high),"a"(dividend.low),"b"(divisor.low));  /*THE HIGH 4 BYTES is the quotient.The low 4 bytes is the remainder.*/
    return ARTIST_ERROR_OK;
}

PUBLIC S4B DivideULLONGU4B(PULLONG quotient,PULLONG remainder,ULLONG dividend,U4B divisor)
{
    ULLONG t;
	t.high=0;t.low=divisor;
	DivideULLONG(quotient,remainder,dividend,t);
	return ARTIST_ERROR_OK;
}

PUBLIC S4B MultiplyULLONG(PULLONG result,ULLONG m1,ULLONG m2)
{
   __asm__ __volatile__("mull %%ebx\n\t":"=d"(result->high),"=a"(result->low):"a"(m1.low),"b"(m2.low));
   return ARTIST_ERROR_OK;
}

PUBLIC S4B MultiplyULLONGU4B(PULLONG result,ULLONG m1,U4B m2)
{
   ULLONG m;m.high=0;m.low=m2;
   MultiplyULLONG(result,m1,m);
   return ARTIST_ERROR_OK;
}

PUBLIC S4B MultiplyU4BU4B(PULLONG result,U4B m1,U4B m2)
{
   ULLONG t1,t2;
   t1.low=m1;t1.high=0;
   t2.low=m2;t2.high=0;
   MultiplyULLONG(result,t1,t2);
   return ARTIST_ERROR_OK;
}
